#!/bin/bash
if [ ! -n "${1}" ] || [ ! -n "${2}" ] || [ ! -n "${3}" ] || [ ! -n "${4}" ];
    then
    echo "ERROR! install extends: param error, request rootPassword,version,schoolCode,sections, your param is : $*"
    exit 0;
fi
schoolCode=${3}
sections=$4

dataPath=/usr/local/data
if [ ! -d "$dataPath" ]; then
        echo "ERROR! $dataPath is not exist."
        exit -1;
fi
rm -rf /usr/local/install
cp -r /usr/local/data /usr/local/install
echo "init extends sections bxn-score" 
echo "param is $*"
sed -i "s/{schoolcode}/$schoolCode/g" /usr/local/install/schoolset/schoolset-bxn-score*.sql
if [ $sections -eq 1 ] || [ $sections -eq 12 ] || [ $sections -eq 13 ] || [ $sections -eq 123 ];then
    echo "has section 1" 
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_data_1.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_portal_1.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_bxn_1.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/schoolset/schoolset-bxn-score1.sql

fi
if [ $sections -eq 2 ] || [ $sections -eq 23 ] || [ $sections -eq 123 ] || [ $sections -eq 12 ];then
    echo "has section 2"
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_data_2.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_portal_2.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_bxn_2.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/schoolset/schoolset-bxn-score2.sql
fi
if [ $sections -eq 3 ] || [ $sections -eq 13 ] || [ $sections -eq 123 ] || [ $sections -eq 23 ];then
    echo "has section 3"
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_data_3.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_portal_3.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/init/bxn-score/${2}/init_bxn_3.sql
        mysql -uroot -p${1} --default-character-set=utf8 < /usr/local/install/schoolset/schoolset-bxn-score3.sql
fi

